package dl.bukkit.myststus;

import dl.bukkit.myststus.loader.LoaderManager;
import dl.bukkit.myststus.logger.Logger;
import lk.vexview.api.VexViewAPI;
import lk.vexview.hud.MinecraftHud;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;

public class MyStatus extends JavaPlugin {

    private static MyStatus inst;
    private LoaderManager loaderManager;

    @Override
    public void onLoad() {
        inst = this;
        this.loaderManager = new LoaderManager(this);
    }

    @Override
    public void onEnable() {
        loaderManager.register();
        loaderManager.staring();
        Logger.pluginInfo();
    }

    @Override
    public void onDisable() {
        loaderManager.stopping();
    }

    public static void runTaskAsynchronously(Runnable runnable) {
        Bukkit.getScheduler().runTaskAsynchronously(inst, runnable);
    }

    public static void reload() {
        for (Player player : new ArrayList<>(Bukkit.getOnlinePlayers())) {
            for (MinecraftHud value : MinecraftHud.values()) {
                VexViewAPI.setMinecraftHudVisible(value, true, player);
            }
        }
        inst.onDisable();
        inst.onLoad();
        inst.onEnable();
    }
}
